package com.baizhi.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * 切面
 */
@Component
public class FirstAspect {


    public void before(JoinPoint jp){
        System.out.println("First前置通知.....");
    }


    public Object around(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("First环绕通知之前....");

        //调用目标方法
        Object proceed = jp.proceed(); //---执行的是目标方法

        System.out.println("First环绕通知之后......");

        return proceed;
    }


    public void afterRuturning(JoinPoint jp,Object msg){
        //获取目标对象

        Class<?> aClass = jp.getTarget().getClass();

        //获取切入点
        String name  =jp.getSignature().getName();
       // System.out.println("afterRuturning......["+aClass+"]...["+name+"]...["+msg+"]");
        System.out.println("First后置通知......");
    }


    public void afterThrow(JoinPoint jp,Throwable e){
        //获取目标对象
        Class<?> aClass = jp.getTarget().getClass();
        //获取切入点
        String name  =jp.getSignature().getName();

        //System.out.println("afterThrow......["+aClass+"]...["+name+"]...["+e+"]");
        System.out.println("First异常通知......");
    }


    public void after(JoinPoint jp){
        //获取目标对象
        Class<?> aClass = jp.getTarget().getClass();
        //获取切入点
        String name  =jp.getSignature().getName();
       // System.out.println("after.......["+aClass+"]...["+name+"]...");
        System.out.println("First最终通知......");
    }
}
